package servlet.PropertyManagementModule.CostManagement;

import bean.dto.CostPage;
import bean.vo.CostOption;
import com.alibaba.fastjson.JSON;
import commons.r.R;
import service.CostManagementService;
import service.impl.CostManagementServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * servlet.PropertyManagementModule.CostManagement
 * User: xlh
 * Date: 2024/12/19 19:10
 * motto:推到高塔
 * Description:
 * Version: V1.0
 */
@WebServlet(name="CostLoadAllServlet",value="/costManage/fetchAllData")
public class CostLoadAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //创建查询实体
        CostPage costPage= new CostPage();
        //设置查询条件
        CostManagementService service=new CostManagementServiceImpl();
        List<CostOption> list=null;
        list = service.loadAll(costPage);

        R r= R.ok().addData("list",list);
        //data={total:,list:} addData
        //响应对象
        PrintWriter writer = response.getWriter();
        String result = JSON.toJSONString(r);
        System.out.println("chazhao"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}

